import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class SetExample2 {

    public static void main(String[] args) {
        Set<Integer> set = new HashSet<>();
        set.add(1);
        set.add(2);
        set.add(3);
        set.add(4);

        Iterator<Integer> iterator = set.iterator();
        System.out.println(iterator.next());

        while (iterator.hasNext()) {
            System.out.print(iterator.next() + " ");
        }
    }
}
